package com.yf.dmp.controller;

import com.alibaba.fastjson.JSON;
import com.yf.dmp.bean.QueryInfo;
import com.yf.dmp.bean.SystemInfo;
import com.yf.dmp.service.SystemInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@CrossOrigin
public class SystemInfoController {

    @Autowired
    SystemInfoService siService;

    @RequestMapping("/systeminfo")
    public String getSystemInfo(QueryInfo queryInfo) {
      return   siService.getSystemInfo(queryInfo);
    }

    @RequestMapping("/addsysteminfo")
    public String addSystemInfo(@RequestBody SystemInfo si) {
        int i = siService.addSystemInfo(si);
        return i > 0 ? "Success" : "Error";
    }

    @RequestMapping("/deletesysteminfo")
    public String deleteSystemInfoById(int id) {
        int i = siService.deleteSystemInfoById(id);
        System.out.println(id + "用户被删除");
        return i > 0 ? "Success" : "Error";
    }

    @RequestMapping("/getupdatesysteminfo")
    public String getUpdateSystemInfo(int id){
        System.out.println(id+"用户进入修改");
        SystemInfo sl = siService.getUpdateSystemInfo(id);
        String jsonstr = JSON.toJSONString(sl);
        return jsonstr;
    }

    @RequestMapping("/updatesysteminfo")
    public String updateSystemInfo(@RequestBody SystemInfo si){
        int i = siService.updateSystemInfo(si);
        return   i>0?"Success":"Error";
    }
}
